﻿namespace OnlineVideos.RingToneEditor
{
   
    using System;
    using System.IO;
    using System.Runtime.InteropServices;


    
    public class WaveFormatExtensible : WaveFormat
    {
        private short wValidBitsPerSample;
        private int dwChannelMask;
        private Guid subFormat;
        private WaveFormatExtensible()
        {
        }

        public WaveFormatExtensible(int rate, int bits, int channels) : base(rate, bits, channels)
        {
            base.waveFormatTag = WaveFormatEncoding.Extensible;
            base.extraSize = 0x16;
            this.wValidBitsPerSample = (short) bits;
            for (int i = 0; i < channels; i++)
            {
                this.dwChannelMask |= ((int) 1) << i;
            }
            if (bits == 0x20)
            {
                this.subFormat = AudioMediaSubtypes.MEDIASUBTYPE_IEEE_FLOAT;
            }
            else
            {
                this.subFormat = AudioMediaSubtypes.MEDIASUBTYPE_PCM;
            }
        }

        public Guid SubFormat
        {
            get
            {
                return this.subFormat;
            }
        }
        public override void Serialize(BinaryWriter writer)
        {
            base.Serialize(writer);
            writer.Write(this.wValidBitsPerSample);
            writer.Write(this.dwChannelMask);
            byte[] buffer = this.subFormat.ToByteArray();
            writer.Write(buffer, 0, buffer.Length);
        }

        public override string ToString()
        {
            return string.Format("{0} wBitsPerSample:{1} dwChannelMask:{2} subFormat:{3} extraSize:{4}", new object[] { base.ToString(), this.wValidBitsPerSample, this.dwChannelMask, this.subFormat, base.extraSize });
        }
    }
}

